<?php
declare (strict_types=1);

namespace app\common\model;

class Role extends Base
{
    protected $name = 'auth_group';

    public static function _delete($param, $admin): array
    {
        parent::startTrans();
        try {
            $info = parent::where(['id' => $param['id']])->find();
            if (empty($info)) {
                throw new \Exception('该管理员角色不存在');
            }
            parent::destroy(['id' => $info->id]);
            if ($admin) {
                Logs::adds('删除管理员角色【' . $info->id . '】【' . $info->title . '】', $admin->id, $admin->admin_name);
            }
            parent::commit();

            return ['code' => 1, 'msg' => '删除成功'];
        } catch (\Exception $e) {
            parent::rollback();

            return ['code' => -1, 'msg' => $e->getMessage()];
        }
    }
}